package com.ivan.stu.notetool.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;


import com.ivan.stu.notetool.R;
import com.ivan.stu.notetool.model.MySubjectBean;

import java.util.List;

/**
 * Created by pengmi on 2018/4/27.
 */

public class NoteSubjectAdapter extends BaseAdapter {

    private Context mContext;
    private List<MySubjectBean> listData;
    private int currentCheckIndex=0;

    public NoteSubjectAdapter(Context mContext, List<MySubjectBean> listData) {
        this.mContext = mContext;
        this.listData = listData;
    }

    @Override
    public int getCount() {
        return listData!=null?listData.size():0;
    }

    @Override
    public Object getItem(int position) {
        return listData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHold vh=null;
        if(convertView==null){
            vh=new ViewHold();
            convertView= LayoutInflater.from(mContext).inflate(R.layout.lgnotelib_item_summary_class,parent,false);
            vh.tv_class_name= (TextView) convertView.findViewById(R.id.tv_class_name);
            vh.img_select= (ImageView) convertView.findViewById(R.id.img_drop_checked);
            convertView.setTag(vh);
        }else{
            vh= (ViewHold) convertView.getTag();
        }
        if(position==currentCheckIndex){
            vh.img_select.setVisibility(View.VISIBLE);
            vh.tv_class_name.setTextColor(Color.parseColor("#17C295"));
        }else{
            vh.tv_class_name.setTextColor(Color.parseColor("#ff111111"));
            vh.img_select.setVisibility(View.INVISIBLE);
        }
        vh.tv_class_name.setText(listData.get(position).getSubjectName());
        return convertView;
    }

    private class ViewHold{
        TextView tv_class_name;
        ImageView img_select;
    }
    public void setCurrentCheckIndex(int currentCheckIndex){
        this.currentCheckIndex=currentCheckIndex;
    }
}
